<template>
	<view class="container">
		<view class="step_one">
			<view class="lay-c-c pd-v-md">
				<text class="title">一. 比赛基本信息设置</text>
			</view>
			<view class="popup_group">
				<view class="popup_group_item">
					<view class="popup_group_item_label">名称</view>
					<view class="popup_group_item_value"><input v-model="setFormData.store_name" type="text" maxlength="32" value="" placeholder="比赛名称" /></view>
				</view>
				
				<view class="popup_group_item">
					<view class="popup_group_item_label">报名开始日期</view>
					<view class="popup_group_item_value">
						<picker mode="date" :value="setFormData.signFromDate" @change="onSignFromDateChange">
							<view class="uni-input">{{setFormData.signFromDate}}</view>
						</picker>
					</view>
				</view>
				
				<view class="popup_group_item">
					<view class="popup_group_item_label">报名结束日期</view>
					<view class="popup_group_item_value">
						<picker mode="date" :value="setFormData.signToDate" @change="onSignToDateChange">
							<view class="uni-input">{{setFormData.signToDate}}</view>
						</picker>
					</view>
				</view>
				
				<view class="popup_group_item">
					<view class="popup_group_item_label">比赛日期</view>
					<view class="popup_group_item_value">
						<picker mode="date" :value="setFormData.raceDate" @change="onRaceDateChange">
							<view class="uni-input">{{setFormData.raceDate}}</view>
						</picker>
					</view>
				</view>
				
				<view class="popup_group_item">
					<view class="popup_group_item_label">价格（元）</view>
					<view class="popup_group_item_value"><input v-model="setFormData.yearlyYpPrice" type="digit" maxlength="5" placeholder="比赛价格" /></view>
				</view>
				
				<view class="popup_group_item">
					<view class="popup_group_item_label">人数</view>
					<view class="popup_group_item_value"><input v-model="setFormData.yearlyYpStock" type="number" maxlength="5" placeholder="比赛人数" /></view>
				</view>
				
			</view>

			<view class="input_content">
				<view class="input_content_describe" style="border-top: 0px;">
					<view class="input_content_describe_title">
						<view class="input_content_describe_title_msg">比赛章程</view>
						<view class="input_content_describe_title_num">
							<text v-if="setFormData.content">{{ setFormData.content.length }}</text>
							<text v-else>0</text>
							/2000
						</view>
					</view>
					<view class="input_content_describe_textarea" style="height: 300px;">
						<textarea style="height: 280px;" v-model="setFormData.content" value="" placeholder="请填写比赛章程" placeholderClass="placeholderClass" maxlength="2000" />
					</view>
				</view>
				
				<view class="photo_count">
					<text class="photo_size">添加主图和轮播图，第1张作为主图。建议：图片尺寸为750*750px</text>
					<view class="input_content_photo">
						<view class="input_content_photo_adPh" v-for="(item, index) in setFormData.imageList" :key="index">				
							<image :src="item" class="myimg2 photos"></image>  			
							<view class="input_content_photo_adPh_jiao" @click="deleteImage(index)"><image src="../static/images/close.png" mode=""></image></view>
						</view>
						<view v-if="setFormData.imageList.length < 9" class="input_content_photo_adPh addBtn" @click="clk">
							<view><image src="../static/images/creamer.png" mode="widthFix"></image></view>
							<view>添加图片</view>
						</view>
					</view>
				</view>
			</view>	
					
			<view class="lay-c-c mg-t-lg pd-v-md">
				<text class="title">二. 场次设置</text>
			</view>
			<view class="popup_group">
				<view class="popup_group_item">
					<view class="popup_group_item_label">场数</view>
					<view class="popup_group_item_value"><input v-model="roundNum" type="number" maxlength="2"/></view>
				</view>
				<view class="popup_group_item">
					<view class="popup_group_item_label">每区人数</view>
					<view class="popup_group_item_value"><input v-model="setFormData.partitionPersons" type="number" maxlength="4"/></view>
				</view>
				<view class="popup_group_item">
					<view class="popup_group_item_label">准备时长(分钟)</view>
					<view class="popup_group_item_value"><input v-model="setFormData.prepairMinutes" type="number" maxlength="4" placeholder="提前摇号时间"/></view>
				</view>
				<view class="popup_group_item">
					<view class="popup_group_item_label">排名方式</view>
					<radio-group @change="onRankTypeChange($event)" style="display: flex;">
						<label style="display: flex;">
							<view><radio value=0 :checked="0==setFormData.rankType" /></view>
							<view>倒积分制</view>
						</label>
						<label style="display: flex; margin-left: 20rpx;">
							<view><radio value=1 :checked="1==setFormData.rankType" /></view>
							<view>累积渔获</view>
						</label>
					</radio-group>
				</view>
				<view class="popup_group_item">
					<view class="popup_group_item_label">撤大边</view>
					<switch :checked="setFormData.bigsideEnable" color="#E93323" style="transform:scale(0.8)" @change="useBigside" />
				</view>
				<view class="popup_group_item">
					<view class="popup_group_item_label">比赛中是否公开成绩</view>
					<switch :checked="setFormData.openScore" color="#E93323" style="transform:scale(0.8)" @change="openScoreChange" />
				</view>
			</view>
			
			<view class="lay-c-c mg-t-lg pd-v-md">
				<text class="title">三. 分区设置</text>
			</view>
			<block v-for="(partition, partitionIdx) in setFormData.partitions" :key="partitionIdx">
				<view style="margin-left: 20rpx; margin-bottom: -20rpx">
					<text class="title">分区{{partitionIdx+1}}</text>
				</view>
				<view class="popup_group">
					<view class="popup_group_item">
						<view class="popup_group_item_label">选择比赛钓塘</view>
						<view class="popup_group_item_value">
							<picker @change="pondPickerChange($event, partitionIdx)" :value="partition.pondIndex" :range="ponds" range-key="storeName">
								<view class="uni-input">{{ponds[partition.pondIndex].storeName}}</view>
							</picker>
						</view>
					</view>
					<view class="popup_group_item">
						<view class="popup_group_item_label">钓位</view>
						<view class="flex">
							<input v-model="partition.fromSeatNo" type="number" maxlength="3" style="width:60rpx;" class="mg-h-md solid radius line-gray"/>
							~
							<input v-model="partition.toSeatNo" type="number" maxlength="3" style="width:60rpx"  class="mg-h-md solid radius line-gray"/>
						</view>
					</view>
					<view class="popup_group_item">
						<view class="popup_group_item_label">钓位间隔</view>
						<view class="flex">
							每
							<input v-model="partition.perPersons" type="number" maxlength="2" style="width:60rpx;" class="mg-h-md solid radius line-gray"/>
							个空
							<input v-model="partition.perPersonsFree" type="number" maxlength="2" style="width:60rpx"  class="mg-h-md solid radius line-gray"/>
							个
						</view>
					</view>
					<view class="popup_group_item">
						<view class="popup_group_item_label">大边位</view>
						<view class="popup_group_item_value"><input v-model="partition.bigsideSeats" type="text" maxlength="255" value="" placeholder="用逗号分隔" /></view>
					</view>
					<view class="popup_group_item">
						<view class="popup_group_item_label">成绩类型</view>
						<radio-group @change="onScoreTypeChange($event, partitionIdx)" style="display: flex;">
							<label style="display: flex;">
								<view><radio value=0 :checked="0==partition.scoreType" /></view>
								<view>按重量</view>
							</label>
							<label style="display: flex; margin-left: 20rpx;">
								<view><radio value=1 :checked="1==partition.scoreType" /></view>
								<view>按尾数</view>
							</label>
						</radio-group>
					</view>
					<view class="popup_group_item" style="display: flex; justify-content: flex-end; padding: 16rpx 30rpx; ">
						<button v-if="partitionIdx>0" class="mini-btn" type="warn" size="mini" @click="delPartition(partitionIdx)" >删除</button>
						<button v-if="partitionIdx==(setFormData.partitions.length-1)" class="mini-btn" type="warn" size="mini" @click="addPartition" style="margin-left: 40rpx;">添加</button>
					</view>
				</view>
			</block>
			
			<view class="lay-c-c mg-t-lg pd-v-md">
				<text class="title">四. 场次时间设置</text>
			</view>
			<view>
				<block v-for="(oneRound, roundIdx) in rounds" :key="roundIdx">
					<view style="margin-left: 20rpx; margin-bottom: -20rpx">
						<text class="title">第{{roundIdx+1}}场</text>
					</view>
					
					<view class="popup_group">
						<view class="popup_group_item">
							<view class="popup_group_item_label">开始时间</view>
							<view class="popup_group_item_value">
								<picker mode="time" :value="oneRound.startTime" @change="onRoundStartTimeChange($event, roundIdx)">
									<view class="uni-input">{{oneRound.startTime}}</view>
								</picker>
							</view>
						</view>
						
						<view class="popup_group_item">
							<view class="popup_group_item_label">结束时间</view>
							<view class="popup_group_item_value">
								<picker mode="time" :value="oneRound.endTime" @change="onRoundEndTimeChange($event, roundIdx)">
									<view class="uni-input">{{oneRound.endTime}}</view>
								</picker>
							</view>
						</view>
					</view>
				</block>
			</view>
					
			<view class="lay-c-c mg-t-lg pd-v-md">
				<text class="title">五. 摇号规则设置</text>
			</view>
			<view>
				<block v-for="(oneRound, roundIdx) in rounds" :key="roundIdx">
					<view style="margin-left: 20rpx; margin-bottom: -20rpx">
						<text class="title">第{{roundIdx+1}}场</text>
					</view>
					
					<view class="popup_group">
						<view class="popup_group_item">
							<view v-if="roundIdx == 0">
								<view>所有运动员抽取：</view>
								<view>抽取：</view>
								<checkbox-group @change="lotItemNewPartitionChange($event, roundIdx, 0)">
									<block v-for="(part, pidx) in oneRound.lotterys[0].new_partitions" :key="pidx">
										<label class="pd-l-lg">
											<checkbox :value="part.partitionNum+''" :checked="part.checked==1" />{{part.partitionNum}} 区
										</label>
									</block>
								</checkbox-group>
							</view>
							<view v-else>
								<block v-for="(lotItem, lotItemIdx) in oneRound.lotterys" :key="lotItemIdx">
									<view class="lay-fs-c">
										<view>摇号项{{lotItemIdx+1}} </view>
										<button v-if="lotItemIdx>0" class="mini-btn" type="warn" size="mini" @click="delLotItem(roundIdx, lotItemIdx)" style="margin-left: 40rpx;">删除</button>
										<button v-if="lotItemIdx==(oneRound.lotterys.length-1)" class="mini-btn" type="warn" size="mini" @click="addLotItem(roundIdx)" style="margin-left: 40rpx;">添加</button>
									</view>
									<view class="pd-l-xl mg-v-xl">
										<view>分区运动员：</view>
										<checkbox-group @change="lotItemPartitionChange($event, roundIdx, lotItemIdx)">
											<block v-for="(part, pidx) in lotItem.partitions" :key="pidx">
												<label class="pd-l-lg">
													<checkbox :value="part.partitionNum+''" :checked="part.checked==1" />{{part.partitionNum}} 区
												</label>
											</block>
										</checkbox-group>
										<view>抽取：</view>
										<checkbox-group @change="lotItemNewPartitionChange($event, roundIdx, lotItemIdx)">
											<block v-for="(part, pidx) in lotItem.new_partitions" :key="pidx">
												<label class="pd-l-lg">
													<checkbox :value="part.partitionNum+''" :checked="part.checked==1" />{{part.partitionNum}} 区
												</label>
											</block>
										</checkbox-group>
									</view>
								</block>
							</view>
						</view>
					</view>
				</block>
			</view>
		</view>

		<view class="handle dobuButton">
			<view class="handle_button" @click="doSubmit">提交</view>
		</view>
		
		<avatar @upload="doUpload" quality="1" ref="avatar" selWidth="250upx" selHeight="250upx"></avatar>
	</view>
</template>

<script>
const app = getApp();
import { navigateTo, serialize, setStorage, getStorage, removeStorage, Loading, hideLoading, Modal } from '../../../libs/uniApi.js';
import { categoryBrandlist, categorySelect, categoryList, attrList, templateList, productDetail, getDeliveryType } from '@/api/product.js';

import {TOKENNAME, HTTP_REQUEST_URL} from '@/config/app.js';
import store from '@/store';
import { productCreate, productUpdate } from 'api/product.js';
import {genDefaultPartition, correctSeats, MyTip} from '../../../components/ssty/common.js';

import {queryGoodsByFshGround} from '@/api/fsh.js'

import avatar from "@/components/yq-avatar/yq-avatar.vue";

export default {
	components: {
		avatar
	},
	data() {
		
		return {
			merId: '',
			product_id: '', // 商品Id
			disModel: false,
			upload_max: 10,
			uploadUrl: `${HTTP_REQUEST_URL}/api/upload/video`,
			setFormData: {
				once_count: '1', // 限购数量

				store_name: '', // 商品名
				signFromDate: new Date().format('yyyy-MM-dd'), 	// 报名开始日期（时间默认为00:00:00开始）
				signToDate: new Date().format('yyyy-MM-dd'), 	// 报名结束日期（时间默认为23:59:59结束）
				raceDate: new Date().format('yyyy-MM-dd'), 		// 比赛日期（时间根据钓塘的固定时间段配置走）
				yearlyYpPrice: undefined, // 价格
				yearlyYpStock: undefined, // 比赛人数
				
				store_info: '比赛',
				content: '', // 比赛详情
				
				imageList: [],
				image: '', //主图
				slider_image: '', // 轮播图
				

				partitionPersons: '',
				prepairMinutes: '',
				rankType: 0,
				bigsideEnable: true,
				openScore: 0,

				partitions: [
					{
						// 比赛钓塘
						pondIndex: 0, // 钓塘索引
						pondProdName: '', // 钓塘名称
						productId: '',// 钓塘商品id
						fromSeatNo: 1,
						toSeatNo: 10,
						perPersons: 1, 
						perPersonsFree: 0,
						bigsideSeats: '',
						scoreType: 0,
					}
				],
			},

			roundNum: 1,
			rounds: [{
				// 场次时间
				startTime: '08:00',
				endTime: '12:00',
				lotterys: [{
					partitions: [{partitionNum: 1, checked: 1}],
					new_partitions: [{partitionNum: 1, checked: 1}]
				}]
			}],
			
			// 钓塘列表
			ponds: [{
				productId: 1,
				storeName: 'A'
			},{
				productId: 2,
				storeName: 'B'
			}],
		};
	},
	onLoad(opt) {
		
		this.merId = opt.mer_id;
		this.product_id = opt.product_id;

		if(getStorage('goodsDis')) { // 商品详情和普通商品共用一个页面
			this.disModel = true;
		}
		
		// 查询钓塘列表
		queryGoodsByFshGround(this.merId, 1).then(res=>{
			this.ponds = [{productId:0, storeName:'请选择比赛要使用的钓塘'}, ...res.entity];
			
			if (this.product_id)
				this.loadDataFromSrv(); 	// 编辑
			// else
				// this.loadDataFromStorage(); // 新建，从cache加载上次编辑的临时数据（暂不支持）
				
		}).catch(e=>{
			console.error(e);
			MyTip("查询钓塘失败，请稍后重试");
		});
	},
	onShow() {
	},

	watch: {
		setFormData: {
			handler(val) {
				console.log("watch setFormData:", JSON.stringify(val));
				setTimeout(()=>{
					setStorage('addRaceFormData', this.setFormData);
				});
			},
			deep: true
		},
		'setFormData.imageList'(val) {
			this.setFormData.image = val.length ? val[0] : '';
			this.setFormData.slider_image = val.length ? serialize(val).splice(1) : [];
		},
		roundNum(newVal, oldVal) {
			console.log("roundNum change: ", newVal, oldVal)
			if(newVal != oldVal && newVal != this.rounds.length) {
				this.resetRounds();
			}
		}
	},
	methods: {
		
		// 从cache获取数据
		async loadDataFromStorage() {
			if (getStorage('addRaceFormData')) {
				this.setFormData = getStorage('addRaceFormData');
			}
		},
		
		// 查询详情数据
		loadDataFromSrv() {
			Loading();
			
			if(getStorage('editRaceFormData')) {
				removeStorage('editRaceFormData'); 
			}

			productDetail(this.merId, this.product_id).then(res => {
				setStorage('editRaceFormData', res.data);
				let editRaceFormData = res.data;
				Object.keys(this.setFormData).forEach(item => {
					this.setFormData[item] = editRaceFormData[item];
				});
				this.setFormData.product_id = this.product_id;
				this.setFormData.imageList = [...(this.setFormData.image ? [this.setFormData.image] : []), ...this.setFormData.slider_image];
				
				this.setFormData.yearlyYpPrice = parseFloat(res.data.yp.price);
				this.setFormData.yearlyYpStock = parseInt(res.data.stock);
				let pos = res.data.yp.sign_from_time.indexOf(" ");
				this.setFormData.signFromDate = res.data.yp.sign_from_time.substr(0, pos);
				pos = res.data.yp.sign_to_time.indexOf(" ");
				this.setFormData.signToDate = res.data.yp.sign_to_time.substr(0, pos);
				this.setFormData.raceDate = res.data.yp.race_date;

				this.roundNum = parseInt(res.data.yp.round_number);
				this.setFormData.partitionPersons = parseInt(res.data.yp.partition_persons);
				this.setFormData.prepairMinutes = parseInt(res.data.yp.prepair_minutes);
				this.setFormData.rankType = parseInt(res.data.yp.rank_type);
				this.setFormData.bigsideEnable = parseInt(res.data.yp.bigside_enable)==1;
				this.setFormData.openScore = parseInt(res.data.yp.open_score)==1;

				this.setFormData.partitions = JSON.parse(res.data.yp.partitions);

				this.rounds = JSON.parse(res.data.yp.rounds);
				
				console.log("loadDataFromSrv, setFormData:", this.setFormData, "rounds:", this.rounds);
				if(res.data.content && (res.data.content.title || res.data.content.image)) {
					setStorage('goodsDis', {store_name: res.data.content.title, imageList:res.data.content.image});
					this.disModel = true;
				}
				
				hideLoading();
			}).catch(e => {
				hideLoading();
				MyTip('加载失败，请稍后重试');
			});
		},
		
		resetRounds(e) {
			// while(parseInt(this.roundNum) > this.rounds.length) {
			// 	this.rounds.push({
			// 		partitions: parts,
			// 		new_partitions: parts
			// 	});
			// }
			// while(parseInt(this.roundNum) < this.rounds.length)
			// 	this.rounds.pop();
			// this.rounds = JSON.parse(JSON.stringify(this.rounds))
			
			this.rounds = []
			let parts = [];
			for(let i = 0; i < this.setFormData.partitions.length; i++)
				parts.push({partitionNum: i+1, checked: 1});
			
			for(let i = 0; i < this.roundNum; i++) {
				this.rounds.push({
					// 场次时间
					startTime: '08:00',
					endTime: '12:00',
					// 摇号规则
					lotterys: [{
						partitions: parts,
						new_partitions: parts
					}]
				});
			}
			
			console.log("resetRounds: ", JSON.stringify(this.rounds))
		},
		
		onRankTypeChange(e) {
			let v = parseInt(e.detail.value);
			this.setFormData.rankType = v;
		},
		
		onScoreTypeChange(e, partitionIdx) {
			let v = parseInt(e.detail.value);
			this.setFormData.partitions[partitionIdx].scoreType = v;
		},
		
		useBigside(e) {
			this.setFormData.bigsideEnable = e.detail.value ? 1: 0;
		},
		
		openScoreChange(e) {
			this.setFormData.openScore = e.detail.value ? 1: 0;
		},
		
		addPartition() {
			this.setFormData.partitions = this.setFormData.partitions.concat({pondIndex: 0});
			this.resetRounds();
		},
		
		delPartition(idx) {
			this.setFormData.partitions.splice(idx, 1);
			this.resetRounds();
		},
		
		delLotItem(roundIdx, lotItemIdx) {
			this.rounds[roundIdx].lotterys.splice(lotItemIdx, 1);
			this.rounds = JSON.parse(JSON.stringify(this.rounds));
		},
		
		addLotItem(roundIdx) {
			let parts = [];
			for(let i = 0; i < this.setFormData.partitions.length; i++)
				parts.push({partitionNum: i+1, checked: 1});
				
			this.rounds[roundIdx].lotterys.push({
				partitions: parts,
				new_partitions: parts
			});
			
			console.log("addLotItem "+roundIdx + "："+JSON.stringify(this.rounds));
			
			this.rounds = JSON.parse(JSON.stringify(this.rounds));
		},
		
		lotItemPartitionChange(e, roundIdx, lotItemIdx) {
			let parts = [];
			for(let i = 0; i < this.setFormData.partitions.length; i++) {
				let checked = undefined !== e.detail.value.find(a=>parseInt(a)==i+1)
				parts.push({partitionNum: i+1, checked: checked});
			}
			
			this.rounds[roundIdx].lotterys[lotItemIdx].partitions = parts;
		},
		
		lotItemNewPartitionChange(e, roundIdx, lotItemIdx) {
			let parts = [];
			for(let i = 0; i < this.setFormData.partitions.length; i++) {
				let checked = undefined !== e.detail.value.find(a=>parseInt(a)==i+1)
				parts.push({partitionNum: i+1, checked: checked});
			}
			
			this.rounds[roundIdx].lotterys[lotItemIdx].new_partitions = parts;
		},
		
		pondPickerChange(e, index) {
			this.setFormData.partitions[index].pondIndex = parseInt(e.target.value);
			this.setFormData.partitions[index].productId = this.ponds[e.target.value].productId;
			this.setFormData.partitions[index].pondProdName = this.ponds[e.target.value].storeName;
			console.log("pondPickerChange: ", index, this.setFormData.partitions)
		},
		
		// 选择图片
		handleChooseImage() {
			let that = this;
			that.$util.uploadImageOne('upload/image', function(res) {
				that.setFormData.imageList.push(res.data.path);
				
			});
		},
		clk() {
			let avatar = this.$refs.avatar;
			avatar.fChooseImg(1,{selWidth: '350upx', selHeight: '350upx', inner: true});
		},
		doUpload(rsp) {
			let that = this
			console.log(rsp);	
			
		
			uni.uploadFile({
				url: HTTP_REQUEST_URL + '/api/upload/image/field',
				filePath: rsp.path,
				name: 'field',
				formData: {
					'filename': rsp.path
				},
				header: {
					// #ifdef MP
					"Content-Type": "mulMyTipart/form-data",
					// #endif
					[TOKENNAME]: 'Bearer ' + store.state.app.token
				},
				success: (uploadFileRes) => {
					console.log(uploadFileRes.data);
					let imgData = JSON.parse(uploadFileRes.data)
					that.setFormData.imageList.push(imgData.data.path)
				},
				complete(res) {
					console.log(res)
				}
			});		
		},
		// 删除图片
		deleteImage(index) {
			this.setFormData.imageList.splice(index, 1);
		},
		
		switchChange(value, item) {
			this.setFormData[item.model] = value ? 1 : 0;
		},
		
		onSignFromDateChange(e) {
			this.setFormData.signFromDate = e.detail.value
		}, 
		
		onSignToDateChange(e) {
			this.setFormData.signToDate = e.detail.value
		},
		
		onRaceDateChange(e) {
			this.setFormData.raceDate = e.detail.value
		},
		
		onRoundStartTimeChange(e, roundIdx) {
			this.rounds[roundIdx].startTime = e.detail.value
		},
		
		onRoundEndTimeChange(e, roundIdx) {
			this.rounds[roundIdx].endTime = e.detail.value
		},
		
		
		check() {
			console.log("check ...", this.setFormData, this.rounds)
			
			let requireData = {
				image: '请选择主图', 
				store_name: '请输入比赛名称',
				yearlyYpPrice: '请输入价格',
				yearlyYpStock: '请输入比赛人数', // 比赛人数可以 > (分区人数x分区)，比如100人的比赛允许120人报名，然后审核pass掉20个
				signFromDate: '请输入报名开始日期',
				signToDate: '请输入报名结束日期',
				raceDate: '请输入比赛日期',
				store_info: '请输入比赛介绍',
				content: '请输入比赛章程',
				partitionPersons: '请输入每区人数',
				// rankType: '请输选择排名方式',
			};
			if(Object.keys(requireData).some(item => {
				if (!this.setFormData[item]) {
					MyTip(requireData[item]);
					return true;
				}
			}))
				return false;
			
			if(this.setFormData.signFromDate > this.setFormData.signToDate) {
				MyTip('报名日期无效：开始日期超过了结束日期');
				return false;
			}
			if(this.setFormData.raceDate < this.setFormData.signToDate) {
				MyTip('比赛日期无效：报名日期超过了比赛日期');
				return false;
			}
			if(this.setFormData.partitions.length < 1) {
				MyTip('没有指定比赛分区');
				return false;
			}
			for(let i = 0; i < this.setFormData.partitions.length; i++) {
				if(!this.setFormData.partitions[i].productId) {
					MyTip('分区'+(i+1)+'没有指定比赛用塘');
					return false;
				}
				let fromSeatNo = parseInt(this.setFormData.partitions[i].fromSeatNo);
				if(!fromSeatNo) {
					MyTip('分区'+(i+1)+'没有指定开始钓位');
					return false;
				}
				this.setFormData.partitions[i].fromSeatNo = fromSeatNo;
				let toSeatNo = parseInt(this.setFormData.partitions[i].toSeatNo);
				if(!toSeatNo) {
					MyTip('分区'+(i+1)+'没有指定结束钓位');
					return false;
				}
				this.setFormData.partitions[i].toSeatNo = toSeatNo;
				if(toSeatNo < fromSeatNo) {
					MyTip('分区'+(i+1)+'指定钓位范围无效');
					return false;
				}
				if((toSeatNo - fromSeatNo + 1) < this.setFormData.partitionPersons) {
					MyTip('分区'+(i+1)+'指定钓位数量不够分区人数');
					return false;
				}
				let perPersons = parseInt(this.setFormData.partitions[i].perPersons);
				this.setFormData.partitions[i].perPersons = perPersons;
				let perPersonsFree = parseInt(this.setFormData.partitions[i].perPersonsFree);
				this.setFormData.partitions[i].perPersonsFree = perPersonsFree;
			}
			if(!this.roundNum) {
				MyTip('没有指定比赛场次');
				return false;
			}
			for(let i = 0; i < this.rounds.length; i++) {
				if(!this.rounds[i].startTime) {
					MyTip('第'+(i+1)+'场没有设置开始时间');
					return false;
				}
				
				if(!this.rounds[i].endTime) {
					MyTip('第'+(i+1)+'场没有设置结束时间');
					return false;
				}
				
				if(!this.rounds[i].lotterys.length) {
					MyTip('第'+(i+1)+'场没有设置摇号项');
					return false;
				}
				
				for(let j = 0; j < this.rounds[i].lotterys.length; j++) {
					if(!this.rounds[i].lotterys[j].partitions) {
						MyTip('第'+(i+1)+'场第'+(j+1)+'摇号项没有指定运动员分区');
						return false;
					}
					if(!this.rounds[i].lotterys[j].new_partitions) {
						MyTip('第'+(i+1)+'场第'+(j+1)+'摇号项没有指定摇号分区');
						return false;
					}	
				}				
			}
			return true;
		},
		
		doSubmit() {
			if(!this.check()) {
				return;
			}
			
			let waitDeleteData = ['addRaceFormData', 'editRaceFormData', 'goodsDis']; // 提交后就把本地缓存数据清空
				
			let postData = {
				...getStorage('addRaceFormData'),
				...this.setFormData,
				partitions: JSON.stringify(this.setFormData.partitions),
				roundNum: this.roundNum,
				rounds: JSON.stringify(this.rounds),
				startTime: this.setFormData.raceDate + ' ' + this.rounds[0].startTime,
				endTime: this.setFormData.raceDate + ' ' + this.rounds[this.rounds.length-1].endTime,
				// content: {
				// 	title: getStorage('goodsDis') ? getStorage('goodsDis').store_name : '',
				// 	image: getStorage('goodsDis') ? getStorage('goodsDis').imageList : []
				// },
				cate_id: app.globalData.race_cate,
			};
			
			if (this.product_id) {
				uni.showLoading({
					title: '正在修改中...'
				});
				
				// #phpcode: 
				// Controller: 
				//		mysvn\ssty\multi-merchant\mallsrv170\app\controller\api\server\StoreProduct.php
				//		public function update($merId, $id, StoreProductValidate $validate)
				//			$data = $this->checkParams($validate); // 接收前端传入的参数
				// ServiceImpl:
				// 		mysvn\ssty\multi-merchant\mallsrv170\app\common\repositories\store\product\ProductRepository.php
				//  	public function edit(int $id, array $data, int $merId, int $productType, $conType = 0)
				// #javacode:
				// Controller:
				//		cmh.ssty.controller.MlsrvController
				//		public R updateYpProd(String yp)
				productUpdate(this.merId, this.product_id, postData)
					.then(res => {
						hideLoading()
						waitDeleteData.forEach(item => {
							if (getStorage(item)) {
								removeStorage(item);
							}
						});
						
						console.log("ypIndex::doSubmit| productUpdate success");
						Modal('提交成功，等待平台审核', '点击确定，返回商品管理', {
							showCancel: false
						}).then(() => {
						uni.redirectTo({
							url:'/pages/product/goodsOnSale/index?mer_id=' + this.merId
						})
						})
					})
					.catch(errMsg => {
						uni.hideLoading();
						console.log("ypIndex::doSubmit| productUpdate fail", errMsg);
						MyTip(errMsg);
					});
			} else {
				uni.showLoading({
					title: '正在创建中...'
				});

				productCreate(this.merId, postData)
					.then(res => {
						hideLoading();
						
						waitDeleteData.forEach(item => {
							if (getStorage(item)) {
								removeStorage(item);
							}
						});
						
						console.log("ypIndex::doSubmit| productCreate success");
						Modal('提交成功，等待平台审核', '点击确定，返回商品管理', {
							showCancel: false,
						}).then(() => {
							uni.redirectTo({
								url:'/pages/product/goodsOnSale/index?mer_id=' + this.merId
							})
						})
					})
					.catch(errMsg => {
						hideLoading();
						console.log("ypIndex::doSubmit| productCreate false", errMsg);
						MyTip(errMsg);
					});
			}
		},
	}
};
</script>

<style lang="scss" scoped>
@import './scss/index.scss';

@import "@/leui.scss";

.content_list {
	width: 710rpx;
	margin: auto;
	padding: 0 20rpx;
	box-sizing: border-box;
	background: #fff;
	margin-top: 31rpx;
	border-radius: 10rpx;
	.content_list_item {
		padding: 32rpx 10rpx;
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #eee;
		.content_list_item_han {
			color: #bbbbbb;
			display: flex;
			align-items: center;
		}
	}
	.content_list_video {
		min-height: 154rpx;
		padding: 23rpx 10rpx;
		display: flex;
		justify-content: space-between;
		.content_list_video_title {
			padding-top: 10rpx;
		}

		.video_list {
			flex: 1;
			display: flex;
			justify-content: flex-end;
			flex-wrap: wrap;
		}
	}
}

.photo {
	border: 1px solid #dddddd;
	opacity: 1;
	border-radius: 8rpx;
	font-size: 28rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	text-align: center;
	// padding: 27rpx 21rpx 24rpx 21rpx;
	width: 150rpx;
	height: 150rpx;
	box-sizing: border-box;
	color: #bbbbbb;
	margin-left: 16rpx;
	position: relative;
	margin-bottom: 12rpx;
	image {
		width: 62rpx;
		margin-bottom: 10rpx;
	}
}

.jiao {
	image {
		position: absolute;
		top: -14rpx;
		right: -14rpx;
		width: 40rpx;
		height: 40rpx;
		border-radius: 50%;
		padding: 8rpx;
		background: #e93323;
		z-index: 999;
	}
	video {
		width: 150rpx;
		height: 150rpx;
	}
}
.container_input {
	background: #fff;
	padding: 0 20rpx;
	width: 710rpx;

	margin: auto;
	margin-top: 31rpx;
	border-radius: 10rpx;
	&_item {
		display: flex;
		height: 106rpx;
		align-items: center;
		.select_and_input {
			display: flex;
			align-items: center;
			justify-content: space-between;
			.greyColor {
				color: #bbbbbb;
			}
		}

		.radio {
			padding: 30rpx 0;
		}

		&_label {
			padding-left: 10rpx;
			color: #333333;
			font-size: 30rpx;
			display: flex;
			align-items: center;
			.select_check {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 40rpx;
				height: 40rpx;
				border: 1px solid #cccccc;
				border-radius: 50%;
				margin-right: 20rpx;

				.iconfont {
					font-size: 24rpx;
				}
			}

			.select {
				background: #e93323;
				border: none;
				.iconfont {
					color: #fff;
				}
			}
		}
		&_value {
			padding-right: 10rpx;
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: flex-end;

			> span:nth-child(1) {
				display: inline-block;
				margin-right: 15rpx;
			}
			.text {
				color: #000;
				display: inline-block;
				max-width: 400rpx;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}

			input {
				text-align: right;
			}

			.select_group {
				display: flex;
			}

			&_select {
				display: flex;
				margin-right: 110rpx;
			}
		}

		.flex_start {
			padding: 0 10rpx;
			margin-top: 40rpx;
			justify-content: flex-start;
		}
	}
	> view:not(:last-child) {
		border-bottom: 1px solid #eeeeee;
	}
}

.inputPlaceHolder {
	color: #bbbbbb;
}

.paddingTop_none {
	padding-top: 0 !important;
}
.marginTop_none {
	margin-top: 0;
}

</style>
